package com.wosai.register.util;

import java.sql.BatchUpdateException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.dao.DataAccessException;

public class ExceptionUtil {
    
    public static List<Integer> extractFailedStatements(DataAccessException dae){
        List<Integer> failed = new ArrayList<Integer>();
        Throwable cause = dae.getCause();
        if (cause instanceof BatchUpdateException){
            BatchUpdateException bue = (BatchUpdateException)cause;
            int[] counts = bue.getUpdateCounts();
            for(int i=0; i<counts.length; ++i) {
                if (counts[i] <= 0) {
                    failed.add(i);
                }
            }
        }
        return failed;
    }
}
